🧭 Kubernetes | February 22, 2021
kubectl 이란?
내가 원하는 걸 요청할 때 사용하는 명령어
기본구조는 kubectl [command] [TYPE] [NAME] [flags]
command
: 자원(object)에 실행할 명령(createm getm delete, edit…)
TYPE
: 자원의 타입(node, pod, service…)
NAME
: 자원의 이름(사용자 정의)
flags
: 부가적으로 설정할 옵션(—help, -o options…)
kubectl api-resources
: 약어 정보 및 리소스들을 확인해 볼 수 있다.kubectl describe node master.example.com
: 해당하는 노드에 대해 자세한 정보를 확인kubectl run webserver --image=nginx:1.14 --port 80
kubectl describe pods
kubectl get pods -o wide
curl
명령어로 파드의 IP 주소를 입력하면 nginx 초기 화면을 확인할 수 있다.elinks
설치: sudo apt-get install elinks
elinks IP주소
: 웹 브라우저에서 보는 화면처럼 표시가 된다.kubectl get pods webserver
을 입력해본다.run
명령어는 하나의 파드만 생성되기 때문에 여러개의 명령어를 사용하기 위해 create
명령어를 사용kubectl create deployment mainui --image=httpd --replicas=3
kubectl get deployments.apps
: 파드 확인kubectl describe deployments.apps mainui
: 자세하게 확인kubectl get pod webserver -o yaml
: yaml 형태로 확인kubectl get pod webserver -o json
: json 형태로 확인kubectl exec webserver -it -- /bin/bash
echo "Hello world" > index.html
: index.html 덮어쓰기exit
명령어로 컨테이너를 빠져나온 뒤, curl IP주소
로 바뀐 것을 확인kubectl logs webserver
kubectl port-forward webserver 8080:80
curl localhost:8080
으로 접속하면 같은 “Hello world”가 출력되는 것을 확인할 수 있다.kubectl edit deployments.apps mainui
: spec 탭에서 replicas 숫자를 수정kubectl get pods
: 파드의 개수 확인kubectl run webserver --image=nginx:1.14 --port 80 --dry-run -o yaml
--dry-run
으로 옵션을 주면 실행이 가능한지 확인할 수 있다.(Ansible 과 똑같음)kubectl run webserver --image=nginx:1.14 --port 80 --dry-run -o yaml > webserver.pod.yaml